<%-- 
    Document   : circle
    Created on : 2011. 12. 5, 오후 4:13:23
    Author     : The Lunatics
--%>

<%@page import="org.json.simple.JSONObject"%>
<%@page import="org.json.simple.JSONArray"%>
<%@page import="controllers.Accessdb"%>
<%@page import="controllers.MainControllerServlet"%>
<%@page import="java.util.*"%>
<%@page import="java.sql.Array"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Circle Info Page</title>


<!-- IMPORT CSS       -->
<link rel="stylesheet" type="text/css" href="default.css" />

<style type="text/css">
/* YOU CAN ADD EVERY CSS STYLES HERE !!!! 
            * I WILL WRAP ALL THIS UP TO ONE CSS FILE LATER
            */
h1 {
	font-size: 30px;
	line-height: 120%;
	margin-bottom: 20px;
	margin-left: 0px;
	margin-right: 0px;
	margin-top: 0px;
}

p {
	margin-bottom: 10px;
	margin-left: 0px;
	margin-right: 0px;
	margin-top: 0px;
}

#userPic {
	float: left;
}

#userDetails {
	float: left;
	margin-left: 20px;
	width: 452px;
}
</style>
</head>
<body>

<%
						// String mysJDBCDriver = "com.mysql.jdbc.Driver";
						// String mysURL = "jdbc:mysql://" + MainControllerServlet.DB_URL;
						// String mysUserID = MainControllerServlet.DB_ID;
						// String mysPassword = MainControllerServlet.DB_PW;
						String circleIdStr;
						if (request.getParameter("circleId") != null) {
							circleIdStr = request.getParameter("circleId").trim();
						} else {
							circleIdStr = "0";
						}
						Integer circleId = Integer.valueOf(circleIdStr);

						System.out.println("circleInfoPage.circleId: " + circleId);

						int i = 0;
						// code start here
						Accessdb db = new Accessdb();
						
%>
	<div id="wrapper">
		<div id="header">
			<%@include file="header.html"%>
		</div>
		<div id="container">
			<div class="content min-width min-height">


				<div id="venueData">
					<div id="venueIcon">
						<img
							src="https://static-s.foursquare.com/img/categories/food/fastfood_64-c55ef2bbbd704cac50dd6e38b9084ad9.png">
					</div>
					<div class="vcard" id="venueDetails">
						<h1 class="fn org">McDonald's</h1>
						<div id="venueContact">
							<p>
								<span class="adr"> <span class="street-address">2324
										Nesconset Hwy</span> (btw Hallock &amp; Stony Brook Rd), <span
									class="locality">Stony Brook</span> , <span class="region">NY</span>
									<span class="postal-code">11790</span>
								</span>
							</p>
							<p>
								(631) 751-1617   <a href="http://twitter.com/McDNYTriState">@McDNYTriState</a>
								<a href="http://www.mcdonaldsnytristate.com/" itemprop="url">mcdonaldsnytristate.com</a>
							</p>
						</div>
					</div>
				</div>

				<div id="postList">
					<%
						//ArrayList<List<String>> postsList = (ArrayList<List<String>>) db.getPostsByCircleId(circleId);
						JSONArray postsList = (JSONArray) db.getPostsByCircleId(circleId);
						//                             java.sql.Connection conn = db.getConnection();
						//                             System.out.println("Connected successfully to database using JConnect");
						//                             //controllers.UsersJpaController user = new UsersJpaController(null, null)
						//                             // Querying.
						//                             conn.setAutoCommit(false);
						//                             String queryStr = " SELECT * "
						//                                     + " FROM `jihhwang`.`posts`"
						//                                     + " WHERE Circle="
						//                                     + "" + circleId + ";";
						//                             System.out.println(queryStr);
						//                             java.sql.Statement stmt1 = conn.createStatement();
						//                             java.sql.ResultSet rs = stmt1.executeQuery(queryStr);
						// 			if (rs.next()) {

						// System.out.println(rs.getCursorName());
						if (postsList == null) {
							System.out.println("No posts");
						} else {
							//ListIterator li = test.listIterator();
							//while (li.hasNext()) { 
							for (int rowIndex = 0; rowIndex < postsList.size() ; rowIndex++) {
								//for (int j = 0; j < (postsList.get(rowIndex)).size(); j++) {
								//PostsFacadeREST postsFacadeREST = new PostsFacadeREST();
								//PostsJpaController postJpaController = new PostsJpaController();
								//postJpaController.getEntityManager().createNamedQuery("Posts.findByCircleId");

								//ArrayList<String> post = postLists.get(rowIndex);
								
								JSONObject content = (JSONObject)(postsList.get(rowIndex));
					%>

					<br /><%=content.toJSONString()%>

					<%
							}
						}
					%>
					<br />
				</div>
				<p id="venueDescription"></p>
				<p class="flagLink">
					<a href="/v/mcdonalds/4b3e27faf964a520f39825e3/flag"
						class="translate" rel="facebox[flagFacebox]">문제 신고</a>
				</p>
			</div>
		</div>
		<!-- container ends -->
	</div>
	</div>

	<div id="footer">
		<%@include file="footer.html"%>
	</div>

</body>
</html>
